/*
 * Cally.h
 *
 *  Created on: Jul 7, 2009
 *      Author: lfor
 */

#ifndef CALLY_H_
#define CALLY_H_

#include "Packet.h"

#include <pthread.h>

// Errors
#define CALLY_OK 						0
#define CALLY_ERROR 					-1
#define CALLY_THREAD_CREATE_ERROR 		1
#define CALLY_NAME_TOO_LONG 	 		2

#define DEFAULT_PORT 2222
#define MAX_FUNC_NUM 10

typedef char* (*CallyFunction)(char*);

typedef struct
{
	CallyFunction Function;
	char Name[MAX_NAME_SIZE];
	char Help[MAX_PARAM_SIZE];
} CallyVectorElement;



class Cally
{
public:
	static Cally * GetInstance();
	int Initialize(int PortNum);
	int Finalize();
	int RegisterFuntion(CallyFunction Func, char * Name, char * Help);

	pthread_t CallyThreadId;

private:
	Cally();
	int List(char * Buffer, int Length);
	int Call(StatusType * Status, char * Name, char * Params, char * Returns, char * Errors, int DataLength, char * Data);

	static CallyVectorElement CallyFunctionVector[MAX_FUNC_NUM];
	static int ElementNumber;

	static void * CallyThread(void * Arg);
	static int ThreadLoop;

	static Cally * Instance;
	int Initialized;
};

#endif /* CALLY_H_ */
